extends Item
var canup:int = 1
var dcnt:int = 0
var bcnt:int = 0
var acnt:int = 0
var tmpinfo = []
var ctrl = globalData.infoDs["g_AneHek"]
var utils = globalData.infoDs["g_AneHekUtils"]
var bufflist = []
func init():
	.init()
	type = config.EQUITYPE_EQUI
	attInit()

func upinfo():
	for i in tmpinfo:
		info = i + "\n" +  info

func delself():
	masCha.delItem(self)
	sys.main.player.delItem(self)
	

func resetdata():
	att.hp = 0
	att.cri = 0
	att.maxHp = 0
	att.suck = 0
	att.atk = 0
	att.mgiSuck =0
	att.def = 0
	att.reHp = 0
	att.atkRan =0
	att.spd = 0
	att.mgiAtk = 0
	att.cd = 0
	att.mgiDef =0
	att.dod = 0
	att.pen = 0
	att.maxHpL = 0
	att.mgiPen = 0
	att.atkL = 0
	att.defL = 0
	att.mgiDefL = 0
	att.penL = 0
	att.mgiPenL = 0
	att.criR = 0
	att.defR = 0
	att.atkR = 0
	dcnt = 0
	bcnt = 0
	acnt = 0
	
func _connect():
	._connect()
	if dcnt:
		if !masCha.is_connected("onAtkChara",self,"run1"):
			masCha.connect("onAtkChara",self,"run1")
		pass
	if bcnt:
		if !masCha.is_connected("onAtkChara",self,"run2"):
			masCha.connect("onAtkChara",self,"run2")
		pass
	if acnt:
		if !masCha.is_connected("onAtkChara",self,"run3"):
			masCha.connect("onAtkChara",self,"run3")
		pass
	bufflist = [
			{"bf":ctrl.b_d,"id":"b_d","cha":"1","val":12 + masCha.att.atk * 0.1},
			{"bf":b_zhonDu,"cha":"1","id":"b_zhonDu"},
			{"bf":ctrl.b_zd,"cha":"1","val":masCha,"id":"b_zd"},
			{"bf":ctrl.b_duwu,"cha":"1","id":"b_duwu"},
			{"bf":ctrl.b_xmjf,"cha":"2","id":"b_xmjf"}
			]

func loadbuff(name,cnt):
	return name.new(cnt)

func run1(atkinfo):
	if !atkinfo.isMiss && atkinfo.atkType == Chara.AtkType.NORMAL:
		for i in range(dcnt):
			if sys.rndPer(33):#待完善
				var nb = sys.rndListItem(bufflist)
				if nb.cha == "1":
					var id = nb.id
					if id == "b_duwu" || id == "b_zhonDu":
						atkinfo.hitCha.addBuff(loadbuff(nb.bf,3))
					else:
						var val = nb.get("val")
						atkinfo.hitCha.addBuff(nb.bf.new(2,val))
				else:
					if masCha.hasBuff(nb.id):continue
					masCha.addBuff(loadbuff(nb.bf,1))
			var d1 = atkinfo.hitCha.hasBuff("b_duwu")
			var d2 = atkinfo.hitCha.hasBuff("b_zhonDu")
			var d3 = atkinfo.hitCha.hasBuff("b_d")
			var d4 = atkinfo.hitCha.hasBuff("b_zd") 
			if d1 && d2:d2.life += d1.life
			if d1 && d3:d3.life += d1.life
			if d1 && d4:d4.life += d1.life
			if d2 && d3:d3.life += d2.life
			if d2 && d4:d4.life += d2.life
			if d3 && d4:masCha.hurtChara(atkinfo.hitCha,(d4.life + d3.life) * 20.0,Chara.HurtType.REAL,Chara.AtkType.EFF)
	pass

func run2(atkinfo):
	if !atkinfo.isMiss && atkinfo.atkType != Chara.AtkType.EFF:
		for i in range(bcnt):
			atkinfo.hitCha.addBuff(b_jieShuang.new(2))
			if sys.rndPer(33):
				atkinfo.hitCha.addBuff(ctrl.b_jhqx.new(1))
			if sys.rndPer(10):
				atkinfo.hitCha.addBuff(ctrl.b_bingdong.new(1))

func run3(atkinfo):
	if !atkinfo.isMiss && atkinfo.atkType != Chara.AtkType.EFF:
		for i in range(acnt):
			if sys.rndPer(50):
				atkinfo.hitCha.addBuff(ctrl.b_zuzhou.new(1,masCha))
			if sys.rndPer(22):
				atkinfo.hitCha.addBuff(ctrl.b_jinliao.new(1))
			if sys.rndPer(3):
				atkinfo.hitCha.addBuff(ctrl.b_jzfh.new(1))

func switchchose(chose):
	call("chose" + str(chose))

var allatt = [
	{"att":"maxHp","val":100},
	{"att":"penL","val":0.05},
	{"att":"mgiPenL","val":0.05},
	{"att":"cd","val":0.1},
	{"att":"def","val":44},
	{"att":"mgiDef","val":44},
	{"att":"suck","val":0.22},
	{"att":"mgiSuck","val":0.22},
	{"att":"atk","val":33},
	{"att":"dod","val":0.05},
	{"att":"pen","val":15},
	{"att":"mgiPen","val":15}
]

func chose1():#魔豌豆的种子
	att.maxHp += 100
	att.penL += 0.05
	att.mgiPenL += 0.05
	pass

func chose2():#精灵龙的龙蛋
	att.cd += 0.1
	att.def += 44
	att.mgiDef += 44
	pass

func chose3():#贪食魔的眼球
	att.suck += 0.22
	att.mgiSuck += 0.22
	att.atk += 33
	pass

func chose4():#神秘的藏宝图
	for i in range(3):
		var tmp = sys.rndListItem(allatt)
		att[tmp.att] += tmp.val
	pass

func chose5():#预言的石刻
	att.dod = 0.05
	att.def = 44
	att.mgiDef = 44
	pass

func chose6():#魔法粉尘·绿
	var tmp = sys.rndListItem(allatt)
	att[tmp.att] += tmp.val
	dcnt += 1
	tmpinfo.append("毒属性：普攻33%附加<随机buff>[多条可重复触发]")
	pass

func chose7():#魔法粉尘·蓝
	var tmp = sys.rndListItem(allatt)
	att[tmp.att] += tmp.val
	bcnt += 1
	tmpinfo.append("冰属性：攻击附带2层<结霜>|33%附加<极寒气息>|10%使敌人获得1层<冰冻>[多条可重复触发]")
	pass

func chose8():#魔法粉尘·紫
	var tmp = sys.rndListItem(allatt)
	att[tmp.att] += tmp.val
	acnt += 1
	tmpinfo.append("暗属性：攻击50%附加1层<诅咒>|22%附加1层<禁疗>|3%附加<禁止复活>[多条可重复触发]")
	pass

func inheritatt(a,b):#a继承b所有属性
	a.att.hp = b.att.hp
	a.att.cri = b.att.cri
	a.att.maxHp = b.att.maxHp
	a.att.suck = b.att.suck
	a.att.atk = b.att.atk
	a.att.mgiSuck = b.att.mgiSuck
	a.att.def = b.att.def
	a.att.reHp = b.att.reHp
	a.att.atkRan = b.att.atkRan
	a.att.spd = b.att.spd
	a.att.mgiAtk = b.att.mgiAtk
	a.att.cd = b.att.cd
	a.att.mgiDef = b.att.mgiDef
	a.att.dod = b.att.dod
	a.att.pen = b.att.pen
	a.att.maxHpL = b.att.maxHpL
	a.att.mgiPen = b.att.mgiPen
	a.att.atkL = b.att.atkL
	a.att.defL = b.att.defL
	a.att.mgiDefL = b.att.mgiDefL
	a.att.penL = b.att.penL
	a.att.mgiPenL = b.att.mgiPenL
	a.att.criR = b.att.criR
	a.att.defR = b.att.defR
	a.att.atkR = b.att.atkR
	a.dcnt = b.dcnt
	a.bcnt = b.bcnt
	a.acnt = b.acnt
	a.tmpinfo = b.tmpinfo

func checkup():
	yield(sys.get_tree().create_timer(0.01),"timeout")
	var item = masCha.items[0]
	if item.id.find("MAX") == -1 && item.has_method("upgradeself"):
		item.upgradeself(self)
		yield(sys.get_tree().create_timer(0.02),"timeout")
		self.delself()
		